﻿using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Windows.Data;

namespace Client.ValueConverters
{
    /// <summary>
    /// MultiBindingConverter
    /// </summary>
    public class MultiBindingConverter : IMultiValueConverter
    {
        /// <summary>
        /// Convert
        /// </summary>
        /// <param name="values"></param>
        /// <param name="targetType"></param>
        /// <param name="parameter"></param>
        /// <param name="culture"></param>
        /// <returns></returns>
        public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
        {
            if (values == null)
            {
                return null;
            }

            object[] r = new object[values.Length];

            for (int i = 0; i < values.Length; i++)
            {
                r[i] = values[i];
            }

            return r;
        }

        /// <summary>
        /// ConvertBack
        /// </summary>
        /// <param name="value"></param>
        /// <param name="targetTypes"></param>
        /// <param name="parameter"></param>
        /// <param name="culture"></param>
        /// <returns></returns>
        public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture)
        {
            if (value == null)
            {
                return null;
            }

            if (value is object[] == false)
            {
                throw new ArgumentException($"期望值是 object[], 但实际是{value.GetType().FullName}");
            }

            var args = value as object[];
            object[] r = new object[args.Length];

            for (int i = 0; i < args.Length; i++)
            {
                r[i] = args[i];
            }

            return args;
        }
    }
}
